package com.chanyachting.emall.domain;

import java.lang.reflect.InvocationTargetException;
import java.util.List;

import org.apache.commons.beanutils.BeanUtils;

import com.chanyachting.emall.dao.ChannelDAO;
import com.chanyachting.emall.domain.base.BaseChannel;

/**
 * This is the object class that relates to the channel table.
 * Any customizations belong here.
 */
public class Channel extends BaseChannel {

/*[CONSTRUCTOR MARKER BEGIN]*/
	public Channel () {
		super();
	}

	/**
	 * Constructor for primary key
	 */
	public Channel (java.lang.Integer _id) {
		super(_id);
		
		Channel channel=(Channel) new ChannelDAO().load(Channel.class, _id);
		
		if(channel!=null){
			
			try {
				BeanUtils.copyProperties(this, channel);
			} catch (IllegalAccessException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			} catch (InvocationTargetException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}
			
		}
	}

/*[CONSTRUCTOR MARKER END]*/
	
	public List getSubList(){
		
		String args []={String.valueOf(this.getId())};
		
		return new ChannelDAO().find("from Channel where parentChannelId=?",args);
	}
	
	public static List parentList(){
		
		return new ChannelDAO().find("from Channel where parentChannelId=0");
	}
	
	public static List list(){
		
		return new ChannelDAO().find("from Channel");
	}
	
}